using System.IO;
using Microsoft.WowAddonStudio.FrameXml.Design.Serialization;
using Microsoft.WowAddonStudio.FrameXml.Serialization;
using NUnit.Framework;

namespace Microsoft.WowAddonStudio.FrameXml.Components.Tests.Inheritance
{
	[TestFixture]
	public class EditBoxSerializationTest : FrameXmlControlTestBase
	{
		private FrameXmlSerializer serializer;

		#region SetUp / TearDown

		/// <summary>
		/// Tests the fixture set up.
		/// </summary>
		[TestFixtureSetUp]
		public void TestFixtureSetUp()
		{
			serializer = new FileFrameXmlSerializer(TestXmlFileName);
		}

		/// <summary>
		/// Sets up.
		/// </summary>
		[SetUp]
		public override void SetUp()
		{
			base.SetUp();
			if (File.Exists(TestXmlFileName)) File.Delete(TestXmlFileName);
			RegisterWowTocFile();
		}

		/// <summary>
		/// Tears down.
		/// </summary>
		[TearDown]
		public override void TearDown()
		{
			base.TearDown();
			if (File.Exists(TestXmlFileName)) File.Delete(TestXmlFileName);
		}

		#endregion

		#region Tests

		/// <summary>
		/// Test_s the edit box serialization.
		/// </summary>
		[Test(Description = "")]
		public void Test_EditBoxSerialization()
		{
			InitializeUi("Data/Inheritance/EditBox.xml");

			((Ui) UiControl.SerializationObject).InheritanceEnabled = false;

			serializer.Serialize(UiControl.SerializationObject as Ui);

			((Ui) UiControl.SerializationObject).InheritanceEnabled = true;

			AssertTextLines("$parent");
		}


		/// <summary>
		/// Test_s the inherited frame serialization.
		/// </summary>
		[Test(Description = "")]
		public void Test_InheritedFrameSerialization()
		{
			InitializeUi("Data/Inheritance/Frame.xml");

			((Ui) UiControl.SerializationObject).InheritanceEnabled = false;

			serializer.Serialize(UiControl.SerializationObject as Ui);

			((Ui) UiControl.SerializationObject).InheritanceEnabled = true;

			WriteControls(UiControl);

			AssertTextLines("$parent");
		}

		/// <summary>
		/// Test_s the texture serialization test.
		/// </summary>
		[Test(Description = "")]
		public void Test_TextureSerializationTest()
		{
			InitializeUi("Data/Inheritance/Texture.xml");

			((Ui) UiControl.SerializationObject).InheritanceEnabled = false;

			serializer.Serialize(UiControl.SerializationObject as Ui);

			((Ui) UiControl.SerializationObject).InheritanceEnabled = true;

			WriteControls(UiControl);

			AssertTextLines("$parent");
		}


		[Test(Description = "")]
		public void Test_VirtualFrameEditBox()
		{
			InitializeUi("Data/Inheritance/VirtualFrameEditBox.xml");

			((Ui) UiControl.SerializationObject).InheritanceEnabled = false;

			serializer.Serialize(UiControl.SerializationObject as Ui);

			((Ui) UiControl.SerializationObject).InheritanceEnabled = true;

			WriteControls(UiControl);

			AssertTextLines("$XY");
		}

		[Test(Description = "")]
		public void Test_TabInheritance()
		{
			InitializeUi("Data/Inheritance/TabInheritance.xml");

			((Ui) UiControl.SerializationObject).InheritanceEnabled = false;

			serializer.Serialize(UiControl.SerializationObject as Ui);

			((Ui) UiControl.SerializationObject).InheritanceEnabled = true;

			WriteControls(UiControl);

			AssertTextLines("$parentLeftDisabled");
			AssertTextLines("$parentMiddleDisabled");
			AssertTextLines("$parentRightDisabled");
			AssertTextLines("$parentLeft");
			AssertTextLines("$parentMiddle");
			AssertTextLines("$parentRight");
			AssertTextLines("$parentLeftDisabled");
			AssertTextLines("$parentMiddleDisabled");
			AssertTextLines("$parentRightDisabled");
		}

		#endregion
	}
}